package com.kuang.pool;

import com.kuang.pool.utils.MyDataSource;
import com.kuang.pool.utils.MyconnectionPool;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by 郭浩 on 2020/9/23 9:18
 */
public class poolTest {
    @Test
    public void testPool(){
        MyconnectionPool myconnectionPool = new MyconnectionPool();
        Connection connection = myconnectionPool.getConnection();
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try {
            preparedStatement = connection.prepareStatement("select * from student");
            resultSet = preparedStatement.executeQuery();
            resultSet.next();
            System.out.println(resultSet.getString("name"));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Test
    public void testDataSource(){
        MyDataSource myDataSource = new MyDataSource();
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        Connection connection = null;
        try {
            connection = myDataSource.getConnection();
            preparedStatement = connection.prepareStatement("select * from student");
            resultSet = preparedStatement.executeQuery();
            resultSet.next();
            System.out.println(resultSet.getString("name"));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
